from selenium import webdriver  # 驱动浏览器
from selenium.webdriver.common.by import By  # 定位
from selenium.webdriver import ActionChains  # 鼠标悬停的包
import time

c = webdriver.Chrome()
c.get('https://www.baidu.com/')
c.maximize_window()
time.sleep(1)

# 悬停设置
setting = c.find_element(By.CSS_SELECTOR, '[id="s-usersetting-top"]')
ActionChains(c).move_to_element(setting).perform()
time.sleep(1)
# 点击搜素设置
search_set = c.find_element(By.CSS_SELECTOR, '[class="set"]')
search_set.click()
time.sleep(1)
# 点击保存设置
save_set = c.find_element(By.LINK_TEXT, '保存设置')
save_set.click()
time.sleep(1)

# 警告框处理  switch_to.alert
# 获取警告框的文本
msg = c.switch_to.alert.text
# 关闭警告框
# c.switch_to.alert.dismiss()
# 确认警告框
c.switch_to.alert.accept()
print(msg)

time.sleep(5)
c.quit()
